package com.zcl.iweibo;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

// 免责声明页面
public class Disclaimer extends Activity{
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 首先显示免责声明
        setContentView(R.layout.disclaimer);
        setTitle(R.string.disclaimer);   
        WebView webView = (WebView)findViewById(R.id.disclaimer_webview);
        webView.setVerticalScrollBarEnabled(true);
        webView.getSettings().setJavaScriptEnabled(true);
        
        File file = new File(getFilesDir().getParentFile()+"/files/protection.htm");
        if (file.exists() == false){
			try {	
				FileOutputStream fos = this.openFileOutput("protection.htm",Context.MODE_WORLD_READABLE);	
				try {
					InputStream is = getResources().openRawResource(R.raw.protection);
					byte[] b = new byte[is.available()];
					is.read(b);
					fos.write(b);
					
					is.close();
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
        }
        webView.loadUrl(Uri.parse("file://"+getFilesDir().getAbsolutePath()+"/protection.htm").toString());      

        Button yesButton = (Button) findViewById(R.id.button_yes);
        yesButton.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View view) {        
//        		setResult(Value.RESULT_CODE_DISCLAIM_ACCEPTE);
//   				finish();
//        	    Preferences.getInstance(getApplicationContext()).setShowFirstPage(false);
        	    startActivity(new Intent(Disclaimer.this, LoginActivity.class));
        	    finish();
        	}
        });
        
        Button exitButton = (Button) findViewById(R.id.button_quit);
        exitButton.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View view) {
//        		setResult(Value.RESULT_CODE_DISCLAIM_REFUSE);
//        		finish();
        	    finish();
        	}
        });
    }
    
    public void onDestroy(){
    	super.onDestroy();  	
    }   
}
